import type { MessageType } from "@/yqSrc/enums";

// 取消readonly属性
export type NoReadonly<T> = {
  -readonly [K in keyof T]: T[K];
};

// 获取VUE组件属性类型
export type VueComponentPropsType<T extends abstract new (...args: any) => any> = Partial<NoReadonly<InstanceType<T>["$props"]>>;

/**
 * 后端接口响应数据
 */
export type TResponse<TData> = {
  success: boolean;
  code: number;
  message?: string;
  messageType?: MessageType;
  data: TData;
};

/**
 * 列表数据
 */
export type TList<TData> = {
  list: TData[];
};

/**
 * 分页数据
 */
export type TPage<TData> = TList<TData> & {
  total: number;
};

/**
 * 后端列表接口响应数据
 */
export type TListResponse<TData> = TResponse<TList<TData>>;

/**
 * 后端分页接口响应数据
 */
export type TPageResponse<TData> = TResponse<TPage<TData>>;

export type FetchDataConfig<TData> = {
  url: string;
  method: "get" | "post";
  params: Record<string, any>;
  converter: (response: TResponse<any>) => TData;
};
